import { reqDeleteOverTimeProjectById, reqDeleteProjectMessageById, reqExamineProject, reqGetInvalidProjectRecord, reqGetOverTimeProjectRecord, reqGetProjectFileList, reqGetProjectListByCondition, reqUpdateCreepFile } from "@/api";
import { Notification ,Message} from "element-ui";
export default({
    namespaced:true,
    actions:{
        async getProjectListByCondition(context,value){
            let result=await reqGetProjectListByCondition(value);
            if(result.code==='200'){
                context.commit('getProjectListByCondition',result.other)
            }else{
                Message({
                    message: '警告!'+'['+result.code+']'+'['+result.message+']',
                    type: 'warning'
                })
                return;
            }
        },
        async getProjectFileList(context){
            let result=await reqGetProjectFileList();
            if(result.code==='200'){
                context.commit('getProjectFileList',result.other)
            }else{
                Message({
                    message: '警告!'+'['+result.code+']'+'['+result.message+']',
                    type: 'warning'
                })
                return;
            }
        },
        async ExamineProjectApply(context,value){
            let result=await reqExamineProject(value);
            if(result.code==='200'){
                context.commit('ExamineProjectApply');
            }else{
                Message({
                    message: '警告!'+'['+result.code+']'+'['+result.message+']',
                    type: 'warning'
                })
                return;
            }
        },
        async getInvalidProjectApplyList(context,value){
            let result=await reqGetInvalidProjectRecord();
            if(result.code==='200'){
                context.commit('getInvalidProjectApplyList',result.other);
            }else{
                Message({
                    message: '警告!'+'['+result.code+']'+'['+result.message+']',
                    type: 'warning'
                })
                return;
            }
        },
        async deleteProjectMessageById(context,value){
            let result=await reqDeleteProjectMessageById(value);
            if(result.code==='200'){
                context.commit('deleteProjectMessageById',value);
            }else{
                Message({
                    message: '警告!'+'['+result.code+']'+'['+result.message+']',
                    type: 'warning'
                })
                return;
            }
        },
        async getOverTimeProjectRecord(context){
            let result=await reqGetOverTimeProjectRecord();
            if(result.code==='200'){
                context.commit('getOverTimeProjectRecord',result.other);
            }else{
                Message({
                    message: '警告!'+'['+result.code+']'+'['+result.message+']',
                    type: 'warning'
                })
                return;
            }
        },
        async deleteOverTimeProjectById(context,value){
            let result=await reqDeleteOverTimeProjectById(value);
            if(result.code==='200'){
                context.commit('deleteOverTimeProjectById');
            }else{
                Message({
                    message: '警告!'+'['+result.code+']'+'['+result.message+']',
                    type: 'warning'
                })
                return;
            }
        }
    },
    mutations:{
        getProjectListByCondition(state,value){
            state.projectList=value.projects;
            state.projectListRows=value.rows;
        },
        getProjectFileList(state,value){
            state.projectFileList=value;
        },
        ExamineProjectApply(){
            location.reload();
        },
        getProjectFileById(state,value){
            let list=state.projectFileList;
            let resultArr=[];
            list.forEach(element => {
                if(element.projectId===value){
                    resultArr.push(element)
                }
            });
            state.projectFileById=resultArr;
        },
        getInvalidProjectApplyList(state,value){
            state.invalidProjectApplyList=value
        },
        deleteProjectMessageById(){
            Notification({
                title:'通知',
                message:'删除成功',
                type:'success'
            });
            setTimeout(()=>{
                location.reload()
            },1000)
        },
        getOverTimeProjectRecord(state,value){
            state.overTimeProjectRecordList=value;
        },
        deleteOverTimeProjectById(){
            Notification({
                title:'通知',
                message:'删除成功',
                type:'success'
            });
            setTimeout(()=>{
                location.reload()
            },1000)
        }
    },
    state:{
        invalidProjectApplyList:[],
        overTimeProjectRecordList:[],
        projectListRows:0,
        projectList:[],
        projectFileList:[],
        projectFileById:[],
        projectStateList:[
            {label:'待审核',value:'0'},
            {label:'审核失败',value:'-1'},
            {label:'审核通过',value:'1'}
        ]
    },
    getters:{
    }
})